// <copyright file="IService.cs" company="EnterpriseApi">
// Copyright (c) EnterpriseApi. All rights reserved.
// </copyright>

using System.Linq.Expressions;

namespace EnterpriseApi.Services;

/// <summary>
/// 通用服务接口，定义基本的业务逻辑操作
/// </summary>
/// <typeparam name="TEntity">实体类型</typeparam>
public interface IService<TEntity> where TEntity : class
{
    /// <summary>
    /// 获取所有实体
    /// </summary>
    /// <returns>实体集合</returns>
    Task<IEnumerable<TEntity>> GetAllAsync();

    /// <summary>
    /// 根据条件获取实体
    /// </summary>
    /// <param name="predicate">查询条件</param>
    /// <returns>符合条件的实体集合</returns>
    Task<IEnumerable<TEntity>> GetByConditionAsync(Expression<Func<TEntity, bool>> predicate);

    /// <summary>
    /// 根据ID获取实体
    /// </summary>
    /// <param name="id">实体ID</param>
    /// <returns>实体对象，如果不存在则返回null</returns>
    Task<TEntity?> GetByIdAsync(int id);

    /// <summary>
    /// 添加实体
    /// </summary>
    /// <param name="entity">要添加的实体</param>
    /// <returns>添加的实体</returns>
    Task<TEntity> AddAsync(TEntity entity);

    /// <summary>
    /// 更新实体
    /// </summary>
    /// <param name="entity">要更新的实体</param>
    /// <returns>更新后的实体</returns>
    Task<TEntity> UpdateAsync(TEntity entity);

    /// <summary>
    /// 删除实体
    /// </summary>
    /// <param name="id">要删除的实体ID</param>
    /// <returns>删除是否成功</returns>
    Task<bool> DeleteAsync(int id);
}